import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';

@Component({
  selector: 'app-my-table',
  templateUrl: './my-table.component.html',
  styleUrls: ['./my-table.component.scss']
})

export class MyTableComponent implements OnInit {


  @Input() colNames: any = [];
  @Input() dataSet = [];
  @Input() operates: any = [];
  @Input() nzNotFoundContent = '暂无数据'
  @Output() _click = new EventEmitter();

  @Input() serial = "序号";

  @Input() isSplice = false; // 是否截断

  @Input() nzLoading = false;
  
  // 分页
  @Input() isPagination = true;
  @Input() nzTotal = 0;
  @Output() _nzPageSizeChange = new EventEmitter();
  @Output() _nzPageIndexChange = new EventEmitter();
  nzPageSize = 5;
  nzPageIndex = 1;

  pageSizeOptions = [2, 5, 10, 15, 20, 25]; // 页数选择器

  constructor() { }

  ngOnInit() {
  }

  parentClick(data: any, i:number){
    let res = {key: i, data: data}
    this._click.emit(res);
  }

  nzPageSizeChange(){
    if(this.nzTotal == 0){
      return ;
    }
    let pageInfo = {
      pageNumber: this.nzPageIndex,
      pageSize: this.nzPageSize
    }
    this._nzPageSizeChange.emit(pageInfo);
  }
  nzPageIndexChange(){
    if(this.nzPageIndex === 0){
      return ;
    }
    let pageInfo = {
      pageNumber: this.nzPageIndex,
      pageSize: this.nzPageSize
    }
    this._nzPageIndexChange.emit(pageInfo)
  }

  

}